---
category: Random
created: '2021-04-10'
title: Generate a random sign
updated: '2021-10-13'
---

**JavaScript version**

```js randomSign.js
const randomSign = () => (Math.random() >= 0.5 ? 1 : -1);
```

**TypeScript version**

```ts randomSign.ts
const randomSign = (): number => (Math.random() >= 0.5 ? 1 : -1);
```
